package com.vote.utils;

import org.apache.log4j.Logger;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import net.paoding.rose.web.Invocation;

public class MsgHelper {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(MsgHelper.class);
	
	public static void info(Invocation inv, String msg){
		inv.addModel("infoMsg", msg);
	}
	
	public static void error(Invocation inv, String msg){
		inv.addModel("errorMsg", msg);
	}
	
	public static String rInfo(String url, String msg){
		try {
			return url+"?infoMsg="+URLEncoder.encode(msg, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			logger.error("url info message encoder fail !!(msg="+msg+")");
			return null;
		}
	}
	
	public static String rError(String url, String msg){
		try {
			return url+"?errorMsg="+URLEncoder.encode(msg, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			logger.error("url error message encoder fail !!(msg="+msg+")");
			return null;
		}
	}
}
